<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <style>
        .error{
            color: red;
            line-height: 20px;
        }
        .search .layui-table{
            margin-top: 0px !important;
        }
        .datacash.layui-table,.datacash .layui-table-view {
            margin-top: 30px !important;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="search" style="float: left;width: 550px">
            <div class="layui-input-inline" style="width: 550px">
                <input type="text" id="name" name="name" autocomplete="off" class="layui-input" placeholder="编码、名称、分类、构件名称"/>
                <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="loadTable()"></i>
            </div>
            <table class="layui-table" id="datatable"></table>
        </div>
        <div style="float:left;width: 50px;margin-top: 18%;padding-left: 15px;">
            <img src="../../common/images/arrow-right-1.png" onclick="addData()" style="height: 40px;">
            <img src="../../common/images/arrow-left-1.png" onclick="removeData()" style="height: 40px;margin-top:40px;">
        </div>
        <div class="datacash" style="float: left;">
            <table class="layui-table" id="cashtable"></table>
        </div>
    </div>
</div>
<script>
    var nodes,tableObj,tableObj1,datas=[],methodid=[];//1为保存2为更新
    $(function () {
        inintTable(datas);

    })
    /* *
     * @Author bxf
     * @Description 加载左侧树
     * @Date 17:46 2019/7/23
     * @param null
     * @return
     */
    function loadTable(node){
        if(node){
            nodes = node;
        }
        var myname = $("#name").val();
        var tableurl = publicUrl+'resmethods/selectListByConditionNotExit';
        layui.use(['form','table'], function(){
            form = layui.form;
            table = layui.table;
            tableObj = table.render({
                elem: '#datatable',
                size: 'sm',
                even: true, //开启隔行背景
                height: 'full-100',
                method: 'post',
                url: tableurl, //stationId='+window.parent.window.parentId,//8AE7DECA-8E41-4FAB-8B30-9FD1B0B7FA33,78A9E5D8-20FB-4436-BBE8-A25EAC38D056
                headers: {"Authorization":getData("Authorization")},
                where:{
                    "id":nodes.id,//用于判断当前专业id
                    "name":myname
                },
                parseData: function(res){ //res 即为原始返回的数据
                    return formatTableParseData(res);
                },
                request: {
                    pageName: 'pageIndex' //页码的参数名称，默认：page
                    ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                response: {
                    statusCode: 2000,
                },
                cols: [[
                    {type:'checkbox',
                        width: 80,
                        align: 'center'},
                    {
                        type: 'numbers',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    }, {
                        field: 'code',
                        title: '编码',
                        width: "18%",
                        sort: true,
                        align: 'center',
                    },{
                        field: 'name',
                        title: '名称',
                        sort: true,
                        width: "18%",
                        align: 'center',
                    }, {
                        field: 'classy',
                        title: '分类',
                        sort: true,
                        width: "16%",
                        align: 'center'
                    },{
                        field: 'elementName',
                        title: '构件名称',
                        sort: true,
                        width: "18%",
                        align: 'center'
                    }]],
                page: true
            });

        });
    }

    /**
     * 初始化右侧table
     * @param data
     */
    function inintTable(data){
        layui.use(['form','table'], function(){
            form = layui.form;
            table = layui.table;
            tableObj1 = table.render({
                elem: '#cashtable',
                size: 'sm',
                even: true, //开启隔行背景
                height: 'full-100',
                limit:10000,
                data:data,
                cols: [[
                    {
                        type:'checkbox',
                        width: 80,
                        align: 'center'
                    },
                    {
                        type: 'numbers',
                        title: '序号',
                        width: 80,
                        align: 'center'
                    }, {
                        field: 'code',
                        title: '编码',
                        width: 100,
                        sort: false,
                        align: 'center',
                    },{
                        field: 'name',
                        title: '名称',
                        sort: false,
                        width: 100,
                        align: 'center',
                    }]],
                page: false
            });

        });
    }

    /**
     * 移除数据
     */
    function removeData(){
        var checkStatus = table.checkStatus('cashtable'); //datatable 即为基础参数 id 对应的值
        for(var i=0;i<checkStatus.data.length;i++){
            var index = methodid.indexOf(checkStatus.data[i].id);
            methodid.splice(index,1);
            datas.splice(index,1);
         }

        inintTable(datas);
    }

    /**
     * 添加数据
     */
    function addData(){
        var checkStatus = table.checkStatus('datatable'); //datatable 即为基础参数 id 对应的值
        for(var i=0;i<checkStatus.data.length;i++){
            if(methodid.indexOf(checkStatus.data[i].id)==-1){
                datas.push(checkStatus.data[i]);
                methodid.push(checkStatus.data[i].id);
            }
        }
        //table.reload('cashtable',{data:datas});
        inintTable(datas);
    }

    /**
     * 添加工艺工法
     * @returns {*}
     */
    function addexitresmethods(){
        if(methodid.length<1){
            alert("请选择工艺工法");
            return false;
        }
        var data = {"disciplineId":nodes.id,"meithodIds":methodid.join(",")}
        var result;
        publicAjax (null,'resmethods/insertRelDisciplinesMethods',data,false,null,function (r) {
            if(r.code==2000){
                laysuccess("添加成功",null);
                result = r;
            }else{
                layerror("添加失败",null);
                result = r;
            }
        });
        return result;
    }


</script>
</body>

</html>
